﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using TestDataCreator;
using System.Text.RegularExpressions;
namespace LPR
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static List<TestDataCreator.DataItem> TESTDATA;

        private void создатьИзНабораФайловВПапкеToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            dlg.ShowDialog();

            ILicenseNumberTester licenseNumberTester = new LicenseNumberTester();

            if (Directory.Exists(dlg.SelectedPath))
            {
                licenseNumberTester.createDataFromFolder(dlg.SelectedPath, true);
                TESTDATA = licenseNumberTester.Clone();

                foreach (var test in TESTDATA)
                {
                    Regex reg = new Regex(@"\x5C");
                    string[] str = reg.Split(test.ImagePath);
                    this.listBox1.Items.Add(str[str.Length-1]);
                }
            
            }



        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (TESTDATA != null)
            {
                this.pictureBox1.Image = Image.FromFile(TESTDATA[listBox1.SelectedIndex].ImagePath);
                //this.pictureBox1.Size = pictureBox1.Image.Size;
                this.textBox1.Text = TESTDATA[listBox1.SelectedIndex].LicenseNumber;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            TESTDATA[listBox1.SelectedIndex].LicenseNumber = textBox1.Text;
        }
    }
}
